package cn.tedu.lbs.marketing.web.controller;

import cn.tedu.lbs.marketing.web.service.CouponService;
import com.tarena.lbs.base.protocol.exception.BusinessException;
import com.tarena.lbs.base.protocol.model.Result;
import com.tarena.lbs.base.protocol.pager.PageResult;
import com.tarena.lbs.pojo.marketing.param.CouponParam;
import com.tarena.lbs.pojo.marketing.query.CouponQuery;
import com.tarena.lbs.pojo.marketing.vo.CouponVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 优惠券业务
 */
@RestController
public class CouponController {
    @Autowired
    private CouponService couponService;
    //商家管理员查询优惠券分页列表
    @PostMapping("/admin/marketing/coupon/info/list")
    public Result<PageResult<CouponVO>> pageList(@RequestBody CouponQuery couponQuery)
        throws BusinessException {
        return new Result<>(couponService.pageList(couponQuery));
    }
    //商家管理员录入提交优惠券表单
    @PostMapping("/admin/marketing/coupon/info/save")
    public Result<Void> save(@RequestBody CouponParam couponParam)
        throws BusinessException {
        couponService.save(couponParam);
        return Result.success();
    }
    //用户点击某个活动的优惠券 查询优惠券详情
    @GetMapping("/admin/marketing/coupon/info/detail/{id}")
    public Result<CouponVO> detail(@PathVariable Integer id)
        throws BusinessException {
        return new Result<>(couponService.detail(id));
    }
}
